﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GatewayInspect.Common;
using System.Configuration;

namespace GatewayInspect
{
    public partial class SetForm : Form
    {
        string code;
        string type;

        public SetForm()
        {
            InitializeComponent();
        }

        private void SetForm_Load(object sender, EventArgs e)
        {
            string strSQL = "select ORGCODE,ORGNAME from T_SYS_ORG";
            DataTable dt = DataAccess.ExecuteDataTable(strSQL);//获取列表
            List<MyItem> list = new List<MyItem>();
            for (int i = 0; i < dt.Rows.Count;i++ )
            {
                string value = dt.Rows[i]["ORGCODE"].ToString().Trim();
                string name = dt.Rows[i]["ORGNAME"].ToString().Trim();
                list.Add(new MyItem(name, value));
            }
            this.comboBox1.DisplayMember = "Name";
            this.comboBox1.ValueMember = "Value";
            this.comboBox1.DataSource = list;
           
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            code = comboBox1.SelectedValue.ToString();
            string strSQL = "select TYPE from T_SYS_ORG where ORGCODE="+code;
            DataTable dt = DataAccess.ExecuteDataTable(strSQL);
            type = dt.Rows[0]["TYPE"].ToString().Trim();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            saveValue("OrgCode", code);
            saveValue("OrgType", type);
            this.Close();
        }
        public void saveValue(string Name, string Value)
        {
            //ConfigurationManager.RefreshSection(Name);
            ConfigurationManager.AppSettings.Set(Name, Value);
            Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
            config.AppSettings.Settings[Name].Value = Value;
            config.Save(ConfigurationSaveMode.Modified);
            //config.fl
            config = null;
        }
    }
    class MyItem
    {
        public MyItem(string name, string value)
        {
            Name = name;
            Value = value;
        }
        public string Name { get; private set; }
        public string Value { get; private set; }
    }
}
